package me.joshua.tools4j.service;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class CrawlService {

	private final static Logger	LOGGER	= Logger.getLogger(CrawlService.class);

	@Cacheable("shared")
	public Document crawl(String url) {
		url = StringUtils.trimToNull(url);
		if (null == url) {
			return null;
		}

		Document doc = null;
		try {
			doc = Jsoup.connect(url).get();
		} catch (Exception e) {
			LOGGER.error("Crawl error url[" + url + "]", e);
		}

		return doc;
	}
}
